package com.sann.config;

import com.sann.condition.LinuxCondition;
import com.sann.condition.MyImportBeanDefinitionRegistrar;
import com.sann.condition.MyImportSelector;
import com.sann.condition.WindowsCondition;
import com.sann.entity.Green;
import com.sann.entity.Person;
import com.sann.entity.Red;
import com.sann.factory.ColorFactoryBean;
import org.springframework.context.annotation.*;

/**
 * 测试注入第三方 Bean的4种方式之方式一：通过在@Import 中指定要注入的 Bean类型
 */
@Configuration
@ComponentScan(value = "com.sann")// MYNOTICE ComponentScan只会扫描Spring的几个固定注解，比如@Controller
@Import({Green.class, Red.class,
        MyImportSelector.class,
        MyImportBeanDefinitionRegistrar.class})
public class MainConfig {

    /**
     * @Conditional 注解将满足条件的 Bean 放进容器
     * @return
     */
    @Bean("Linus")
    @Conditional(LinuxCondition.class)
    public Person person01(){
        return new Person("Linus", 48);
    }

    @Bean("Bill")
    @Conditional(WindowsCondition.class)
    public Person person02(){
        return new Person("Bill Gates", 62);
    }


    @Bean(name = "colorBean")
    public ColorFactoryBean createColorBean(){
        return new ColorFactoryBean();
    }
}
